{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>捐赠管理列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-9">
                        <form id="layuiForm">
                            <div class="col-sm-8">
                                <div class="input-group" >
                                    <input type="text"  id="start" name="start"  class="form-control layer-date search" placeholder="支付日期" />
                                    <span class="input-group-addon">到</span>
                                    <input type="text"  id="end" name="end"  class="form-control layer-date search" placeholder="支付日期" />
                                </div>
                            </div>


                            <div class="col-sm-4">
                                <div class="input-group" >
                                    <input type="text" id="key" class="form-control search" name="key" value="" placeholder="订单编号"/>
                                    <span class="input-group-btn">
                                        <a  class="btn btn-primary layuiBtn" data-type="reload"><i class="fa fa-search"></i> 搜索</a>
                                    </span>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="__JS__/My97DatePicker/WdatePicker.js"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //前后若干天可选，这里以7天为例
        laydate.render({
            elem: '#start'
            ,type: 'datetime'
        });
        //前后若干天可选，这里以7天为例
        laydate.render({
            elem: '#end'
            ,type: 'datetime'
            ,done: function(value, date, endDate){
                var start_time = $("#start_time").val();
                var time1 = Date.parse(new Date(start_time));
                var time2 = Date.parse(new Date(value));
                var nDays = Math.abs(parseInt((time2 - time1)/1000/3600/24));
                if(nDays>30){
                    layer.msg("时间间隔不能超过30天");
                    laydate.value();
                    return false;
                }
            }
        });
    });
</script>
<script>
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("reward/index")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 80
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , text: {
                none: '暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 60, title: '序号'}
                , {field: 'donate_id', width: 60, title: 'ID', sort: true, align: 'center'}
                , {field: 'donate_number', width: 230, title: '订单编号', align: 'center'}
                , {field: 'donate_money', width: 130, title: '金额', align: 'center'}
                , {field: 'order_type', width: 130, title: '支付方式', align: 'center',templet:"#order_type"}
                , {field: 'pay_time', width: 230, title: '支付时间', align: 'center'}
                , {field: 'user_username', width: 130, title: '购买人昵称', align: 'center'}
            ]]
            ,done: function (res, curr, count) {
                $.each(res.data,function(index,item){
                    $('#view_'+item['order_id']).viewer({
                        url: 'data-original',
                    });
                });
            }
        });
        //搜索表格重载
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where:$('#layuiForm').parseForm()
                });
            }

        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['donate_id'])
            });
            return ids;
        }
    });
</script>

<script type="text/html" id="order_type">
    {{# if(d.donate_type == 1){ }}
    <span style="color:#ec4758">支付宝</span>
    {{# } else {}}
    <span style="color:#ec4758">微信</span>
    {{# } }}
</script>

</body>
</html>